package com.leyou.trade.web;

import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderFormDTO;
import com.leyou.trade.entity.OrderLogistics;
import com.leyou.trade.service.OrderLogisticsService;
import com.leyou.trade.service.OrderService;
import com.leyou.user.client.UserClient;
import com.leyou.user.dto.AddressDTO;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderLogisticsService orderLogisticsService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserClient userClient;

    /**
     * 创建订单
     * @param orderDto
     * @return
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody @Valid OrderFormDTO orderDto){
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.createOrder(orderDto));
    }

    /**
     * 根据id查询订单
     * @param orderId
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderDTO> queryOrderById(@PathVariable("id")Long orderId){
        return ResponseEntity.ok(orderService.queryOrderById(orderId));
    }

    /**
     * 查询订单支付状态
     * @param orderId 订单id
     * @return 状态值
     */
    @GetMapping("status/{id}")
    public ResponseEntity<Integer> queryOrderStatus(@PathVariable("id")Long orderId){
        return ResponseEntity.ok(orderService.queryOrderStatus(orderId));
    }
}
